var $addExitModal;
var $$scope;
var $CertusJsonAjax;
var dataInit;
function toExit($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q,addExitModal){
    dataInit = CertusJsonAjax.dataInit("exitUserList",{onPost:"sb","areaSelect":"XZZX-LZGL"},indColumns,'indContainer1','indToolBarContainer1');
    $$scope = $scope;
    $addExitModal = addExitModal;
    $CertusJsonAjax =CertusJsonAjax;

    $$scope.modalContent = {};

    $$scope.addExit = function(){
        $(".addExitCls").show();
        $scope.modalContent = {};
        $("#empId").val("")
        $("#userName").val("")
        $("#empName").val("")
    }

    $scope.startExitSub = function (a) {
        layer.confirm('确定将'+$("#userName").val()+"离职", {
            btn: ['确认', '取消']
        },function(){
            if(certusValidateNotnullPolyfill()){
                CertusJsonAjax.ajax("startExitUser",$scope.modalContent,function(res){
                    if(res.data == "success"){
                        layer.msg("离职成功");
                        $(".addExitCls").hide();
                        dataInit.refresh(true);
                    }else if(res.data == "dont"){
                        layer.msg("人员不存在")
                    }else if(res.data == "failed"){
                        layer.msg("离职失败")
                    }
                })
            }
        },function(){

        })

    }

    $scope.cancel = function(){
        $(".addExitCls").hide();
    }

  // 成员权限
// 员工姓名-客户自动补全
    CertusFormAjax.ajax("findSpUserList4", {"areaSelect":"XZZX-LZGL"}, function (response) {
        var nhlTeams = [];
        var data = response.data;
        for (var i = 0; i < data.length; i++) {
            var arr = {};

            arr.name = data[i].userName + "[" + data[i].positonName + "]("+data[i].userId+")";
            arr.id = data[i].userId;
            arr.userName = data[i].userName;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {

            return {
                value: obj.name,
                data: { category: obj.id,userName: obj.userName}
            };
        });
        // Initialize autocomplete with local lookup:
        $('#empName').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {

                $("#empId").val(suggestion.data.category);
                $("#userName").val(suggestion.data.userName);
                $scope.modalContent.userId = suggestion.data.category;
                $scope.modalContent.userName = suggestion.data.userName;

                CertusFormAjax.ajax("relatedProjMemberName",{userId:suggestion.data.category},function(res){
                    ;
                    $scope.modalContent.proMembers = res.data;
                })
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });

    CertusJsonAjax.initBaseAuthority($scope);

    CertusFormAjax.ajax("stscompSelectByAutho", {"areaSelect":"XZZX-LZGL"}, function (res) {
        $scope.belongCompanyCodeSelect = res.data;
        $scope.companySelect = res.data;
    })

    $scope.companySelect = [
        {name:"赛特斯南京",code:"STSNJ"},
        {name:"赛特斯广东",code:"STSGD"},
        {name:"赛特斯上海",code:"STSSH"},
        {name:"赛特斯北京",code:"STSBJ"},
        /*     {name:"赛特斯南京",code:"STSNJ"},
         {name:"赛特斯北京",code:"STSBJ"},
         {name:"赛特斯上海",code:"STSSH"},*/
        {name:"浩方科技",code:"HFKJ"},
        {name:"浩方信息",code:"HFXX"}
    ]

    $scope.userSelect = {onPost:"sb","areaSelect":"XZZX-LZGL"}

    $scope.searchNewUser = function(){
        dataInit.parameters = $scope.userSelect;
        dataInit.refresh(true);
    }
}

// function startExit(userId,userName){
// //打开弹框
//     // $$scope.modalContent = data.data;
//     $$scope.ok = function () {
//         $modalInstance.close(); // 点击确认后关闭弹窗
//     };
//
//     var modalContent = {userName:userName,userId:userId};
//
//     // modalContent.startExitSub = function(){
//     //
//     // }
//
//
//     $addExitModal.openConfirmWindow($$scope, modalContent,$CertusJsonAjax)
//
// }

function infoExit($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q,$filter){
    var userId = $routeParams.userId;
    $$scope = $scope;

    $scope.belongCompanyCodeSelect = [
        {name:"赛特斯广东",code:"STSGD"},
        {name:"赛特斯南京",code:"STSNJ"},
        {name:"赛特斯北京",code:"STSBJ"},
        {name:"赛特斯上海",code:"STSSH"},
        {name:"浩方科技",code:"HFKJ"},
        {name:"浩方信息",code:"HFXX"}
    ]
    $scope.getBelongCompanyName = function(companyCode){
        if(companyCode == "STSJT"){
            return "赛特斯集团";
        }else if(companyCode == "STSGD"){
            return "赛特斯广东";
        }else if(companyCode == "HFKJ"){
            return "浩方科技";
        }else if(companyCode == "HFXX"){
            return "浩方信息";
        }else if(companyCode == "STSBJ"){
            return "赛特斯北京";
        }else if(companyCode == "STSNJ"){
            return "赛特斯南京";
        }else if(companyCode == "STSSH"){
            return "赛特斯上海";
        }
    }

    $scope.getDate = function(a){

      $scope.rzlcStepEntity.baseUser.firstWorkTime =   $filter("date")(a, "yyyy-MM-dd");
    }
    $scope.sfzddnSelect = [
        {name:"待定",code:"待定"},
        {name:"带",code:"带"},
        {name:"不带",code:"不带"},
    ]

    CertusFormAjax.ajax("userDetailById",{userId:userId},function(res){

        $scope.companySelect = [
            {name:"赛特斯集团",code:"STSJT"},
            {name:"赛特斯广东",code:"STSGD"},
/*            {name:"赛特斯南京",code:"STSNJ"},
            {name:"赛特斯北京",code:"STSBJ"},
            {name:"赛特斯上海",code:"STSSH"},*/
            {name:"浩方科技",code:"HFKJ"},
            {name:"浩方信息",code:"HFXX"}
        ]
        $scope.getSex = function(a){
            if(a == 1){
                return "男";
            }else{
                return "女";
            }
        }

        $scope.departmentChange = function(a){
            for(var xxxx in $scope.departmentSelect){
                if($scope.departmentSelect[xxxx].departmentCode == $scope.rzlcStepEntity.baseUser.departmentUser.departmentCode){
                    $scope.rzlcStepEntity.baseUser.departmentUser.departmentName = $scope.departmentSelect[xxxx].departmentName;
                }
            }
        }

        //性别 select
        $scope.sexSelect = [
            {name:"男",code:"1"},
            {name:"女",code:"0"}
        ]

        //结婚情况
        $scope.marriageSelect = [
            {name:"已婚",code:"1"},
            {name:"未婚",code:"0"},
            {name:"已婚已育",code:"2"}
        ]

        $scope.getMarriage = function(a){
            if(a == 1){
                return "已婚";
            }else if(a == 0 ){
                return "未婚";
            }else if(a == 2){
                return "已婚已育";
            }

            return "未婚";
        }
        //初始化 数据

        $scope.rzlcStepEntity = res.data;
        $scope.rzlcStepEntity.baseUser.firstWorkTime = $scope.rzlcStepEntity.baseUser.firstWorkTime.split(" ")[0]
        $scope.rzlcStepEntity.baseUser.sex =  $scope.rzlcStepEntity.baseUser.sex+"";
        $scope.rzlcStepEntity.baseUser.isMarriage =  $scope.rzlcStepEntity.baseUser.isMarriage+"";
        $scope.processCCBXTrace = res.data.processs;

        for(var cs in $$scope.companySelect){
            if($scope.companySelect[cs].code == $scope.rzlcStepEntity.baseUser.belongCompanyCode){
                $scope.rzlcStepEntity.baseUser.departmentUser.companyName = $scope.companySelect[cs].name;
            }
        }
    })
}

function initMyself(id){
    var picker1 = $('#'+id).datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $$scope.modalContent.lastDate = result;
            $$scope.$apply();
        }
    })


    $($('#'+id)).focus();

}

function initMyself1(id){
    var picker1 = $('#'+id).datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $$scope.modalContent.endMonth = result;
            $$scope.$apply();
        }
    })


    $($('#'+id)).focus();

}